/**
 * 全局事件监听器
 */
class EventListener {

  constructor () {
    // 事件监听映射表
    this.callbacks = { }
  }

  /**
   * 添加事件监听
   * @param {*} eventName 
   * @param {*} callback 
   */
  addListener (eventName, callback) {
    this.callbacks[eventName] = callback
  }

  /**
   * 移除事件监听
   * @param {*} eventName 
   */
  removeListener (eventName) {
    delete this.callbacks[eventName]
  }

  /**
   * 触发事件监听
   * @param {*} eventName 
   * @param {*} params 
   */
  triggerEvent (eventName, params) {
    const callback = this.callbacks[eventName]
    if (typeof callback === 'function') {
      callback(params)
    }
  }

}

export default EventListener